"""
用户偏好设置数据模型
"""
from typing import Optional
from pydantic import BaseModel, Field
from datetime import datetime
from app.models.settings import ThemeType, LanguageType


class UserPreferences(BaseModel):
    """用户偏好设置"""
    theme: Optional[ThemeType] = Field(default=ThemeType.LIGHT, description="主题设置: light, dark, auto")
    language: Optional[LanguageType] = Field(default=LanguageType.ZH_CN, description="语言设置")
    timezone: Optional[str] = Field(default="Asia/Shanghai", description="时区设置")
    
    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat() if v else None
        }


class UserPreferencesUpdate(BaseModel):
    """用户偏好设置更新"""
    theme: Optional[ThemeType] = Field(None, description="主题设置: light, dark, auto")
    language: Optional[LanguageType] = Field(None, description="语言设置")
    timezone: Optional[str] = Field(None, description="时区设置")
    
    class Config:
        extra = "allow"  # 允许额外字段，以便未来扩展

